package com.denny.devdemo.touchevent;

import com.denny.devdemo.util.LogUtils;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;

public class DispatcherTouchEventAcitivy extends Activity{

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		MyViewGroup viewGroup = new MyViewGroup(this);
		viewGroup.setBackgroundColor(Color.GREEN);
		MyView view = new MyView(this);
		view.setBackgroundColor(Color.BLUE);
		RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(300,300);
		params.addRule(RelativeLayout.CENTER_IN_PARENT);
		viewGroup.addView(view, params);
		setContentView(viewGroup);
		
	}
	
	class MyViewGroup extends RelativeLayout{

		public MyViewGroup(Context context) {
			super(context);
		}
		

		public MyViewGroup(Context context, AttributeSet attrs) {
			super(context, attrs);
		}


		@Override
		protected void onLayout(boolean changed, int l, int t, int r, int b) {
			super.onLayout(changed, l, t, r, b);
		}
		
		@Override
		public boolean dispatchTouchEvent(MotionEvent ev) {
			LogUtils.e("ViewGroup dispatchTouchEvent");
			super.dispatchTouchEvent(ev);
			return false;
		}
		@Override
		public boolean onInterceptTouchEvent(MotionEvent ev) {
			LogUtils.e("ViewGroup onInterceptTouchEvent");
			return false;
		}
		@Override
		public boolean onTouchEvent(MotionEvent event) {
			LogUtils.e("ViewGroup onTouchEvent");
			return false;
		}
		
	}
	
	class MyView extends View{

		public MyView(Context context, AttributeSet attrs) {
			super(context, attrs);
		}
		
		public MyView(Context context) {
			super(context);
		}
		
		@Override
		public boolean dispatchTouchEvent(MotionEvent event) {
			LogUtils.e("View dispatchTouchEvent");
			super.dispatchTouchEvent(event);
			return false;
		}
		
		@Override
		public boolean onTouchEvent(MotionEvent event) {
			LogUtils.e("View onTouchEvent");
//			super.onTouchEvent(event);
			return false;
		}
		
	}
}
